import React from 'react'
import {useDispatch,useSelector} from 'react-redux'
import {increment} from '../../store/slice/countSlice'

/* 
  react-redux提供了两个hook 用来操作redux
    -useDispatch() 得到一个dispatch方法
    -useSelector() 参数是一个回调函数,回调函数的形参就是store中的数据

*/


export default function Count() {
  //得到一个方法用来改变状态的值
  const dispatch = useDispatch()

  const count = useSelector(state => state.count.count)


    const incrementHandle = ()=>{
      // dispatch(increment(1))

    }

    const decreamentHandle = ()=>{
 
    }

    const ifOddDecrementHandle = ()=>{

    }

    const waitDecrementHandle = ()=>{

    }



  return (
    <div>
        <h1>我是Count组件 我的值是{count}</h1>
        <h2>当前电影总数是{}</h2>
        <div>
            <button onClick={incrementHandle}>累加</button>
            <button onClick={decreamentHandle}>累减</button>
            <button onClick={ifOddDecrementHandle}>如果是奇数再加1</button>
            <button onClick={waitDecrementHandle}>等2s再加1</button>
        </div>
    </div>
  )
}
